package com.javaspeak.designpatterns.go4.behavioural.state;

/**
 * This is the state object for the Standard Bank Account Type where the
 * criteria for having one is determined by the current annual Salary.  This
 * state object will be automatically upgraded to a PremiereAccountState if the
 * salary raises above the salary defined in the enum:
 * <p>
 * SalaryGrade.PREMIERE_ACCOUNT.getSalary().
 * <p>
 * Similarly the account will be automatically downgraded to a
 * StarterAccountState if the salary drops below
 * <p>
 * SalaryGrade.STANDARD_ACCOUNT.getSalary()
 * <p>
 * The other method calls do not result in the State Object being switched
 * for another one.  However the other methods have different method
 * implementations amongst the state objects. For example calling getOverdraft()
 * on a PremierAccountState gives an overdraft of 5000 while calling
 * getOverdraft() on StandardAccountState gives an overdraft of 700.
 *
 * @author John Dickerson
 */
public class StandardAccountState extends AbstractAccountState {

    /**
     * Constructor
     *
     * @param salary Salary
     * @param balance Bank Account Balance
     */
    public StandardAccountState( int salary, float balance ){

        super( salary, balance );
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.state.
     *      State#setSalary(com.javaspeak.designpatterns.go4.behavioural.
     *          state.StateContext, int)
     */
    @Override
    public void setSalary( StateContext stateContext, int salary ) {

        if ( salary >= SalaryGrade.PREMIERE_ACCOUNT.getSalary() ){

            stateContext.changeState(
                    new PremiereAccountState( salary, balance ) );
        }
        else if ( ! ( salary >= SalaryGrade.STANDARD_ACCOUNT.getSalary() ) ){

            stateContext.changeState(
                    new StarterAccountState( salary, balance ) );
        }
        else {

            this.salary = salary;
        }
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.state.
     *      State#getOverdraft()
     */
    @Override
    public int getOverdraft() {

        return 700;
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.state.
     *      State#getAccountName()
     */
    @Override
    public String getAccountName() {

        return "Standard Account";
    }
}
